package com.lam.framework.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.lam.common.components.data.DataInjectUtil;
import com.lam.common.utils.DateUtil;

/**
 * 
 */
@Order(30)
@Aspect
@Component
public class DataInjectAspect {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Pointcut("@annotation(com.lam.common.components.data.annotation.AutoDataInject)")
	public void excudeService() {
	}

	@Around("excudeService()")
	public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
		Object result = joinPoint.proceed();
		if (DataInjectUtil.supportDataType(result)) {
			long start = System.currentTimeMillis();
			result = DataInjectUtil.injectJavaObject(result);
			long end = System.currentTimeMillis();
			logger.info("自动注入数据完成，  耗时:{}", DateUtil.convertTimeLong(end - start));
		}
		return result;
	}
	
}
